# Recreate Figure S1
#### libs ----
library(here)
library(tidyverse)
library(haven)


#### data ----
data <- read_dta(file = 'data/modified data/us_election_results.dta')

#### subset ----
data <- data %>%  
  rowwise() %>% 
  mutate(vbm = (state %in% c("CA", "OR", "HI", "CO", "UT", "WA"))) %>% 
  ungroup()

data_sum <- data %>% 
  filter(year >=1990, !is.na(pres_vs_)) %>% 
  group_by(year, vbm) %>% 
  summarize(vs = weighted.mean(pres_vs_, w= total_votes_, na.rm=T))


# Plot --------------------------------------------------------------------
data_sum %>% ggplot(aes(x = year, y = vs, color = vbm)) +
  geom_point() +
  geom_line() +
  theme_bw() +
  labs(x = 'Year', y = 'Dem Vote Share, Pres') +
  scale_x_continuous(breaks = seq(1992,2016,4), limits = c(1992, 2016)) + 
  lims(y = c(0.44, 0.61)) + 
  theme(legend.position = 'none') +
  annotate('text', x = 2000, y = .56, label = 'VBM States', color = '#00BFC4') +
  annotate('text', x = 2000, y = .48, label = 'Non-VBM States', color = '#F8766D') +
  ggsave('repfig/figureS1.png', width = 6, height = 4, units = 'in')
  

